from cfg.exts import db
import sqlalchemy as sql
from datetime import datetime


# 模型
# 用户
class UserModel(db.Model):
    __tablename__ = "user"
    id = sql.Column(sql.BIGINT, primary_key=True, autoincrement=True)
    username = sql.Column(sql.VARCHAR(100), nullable=False)
    password = sql.Column(sql.VARCHAR(120), nullable=False)
    email = sql.Column(sql.VARCHAR(100), nullable=False, unique=True)
    join_time = sql.Column(sql.DateTime, default=datetime.now)
    age = sql.Column(sql.Integer, nullable=False)
    gender = sql.Column(sql.CHAR(1), default='男')
    tel = sql.Column(sql.VARCHAR(12), nullable=False)

    def toStr(self):
        return {
            "id": self.id,
            "username": self.username,
            "password": self.password,
            "email": self.email,
            "join_time": self.join_time,
            "age": self.age,
            "gender": self.gender,
            "tel": self.tel
        }
